import { Component } from '@angular/core';
import { NbAuthResult, NbLoginComponent } from '@nebular/auth';
import { UserLoginDto } from '@nx-chat/common/dto';

@Component({
  selector: 'chat-login',
  templateUrl: './login.component.html',
})
export class LoginComponent extends NbLoginComponent {

  public user: UserLoginDto;

  login() {
    this.service.authenticate('email', this.user)
      .subscribe((authResult: NbAuthResult) => {
        if (authResult.isSuccess()) {
          this.messages.push(...authResult.getMessages());
          this.router.navigate([authResult.getRedirect()]);
        } else {
          this.errors.push(...authResult.getErrors());
        }
      })
  }

}
